use crate::ades::{Padding, aes_enc, aes_dec};
use ext::{no_std::{functions::ext::Curry, pipelines::pipe::Pipe}, val};
use std::fs;

pub fn aes(r#in: String, out: String, aes: String, encrypt: bool) {
    // Read file data & Write file as partially applied function:
    val!(
        data = fs::read(r#in).unwrap();
        write = |text| fs::write.curryr()(text)(out).unwrap());

    // Initialize the remaining arguments:
    aes.padding(32).as_bytes().pipe(|key| {
        // Crypto as partially applied function:
        val!(
            aes_enc = |data| aes_enc(key)(data);
            aes_dec = |data| aes_dec(key)(data));

        // Encryption and decryption:
        match encrypt {
            true => aes_enc(&data).pipe(write),
            false => aes_dec(&data).pipe(write)
        }
    })
}
